import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      // 添加一个别名 "@", 指向项目的src目录
      '@': path.resolve(__dirname, 'src'),
    },
  },
  css: {
    preprocessorOptions: {
    }
  },
  // 配置服务器的代理设置
  server: {
    proxy: {
      "/api": {
        target: "https://www.primerbanks.com",
        changeOrigin: true,
        secure: false, // 如果目标服务器使用自签名证书，设置为false
        rewrite: (path) => path.replace(/^\/api/, ''), // 移除/api前缀
        configure: (proxy, options) => {
          proxy.on('error', (err, req, res) => {
            console.log('proxy error', err);
          });
          proxy.on('proxyReq', (proxyReq, req, res) => {
            console.log('Sending Request to the Target:', req.method, req.url);
          });
          proxy.on('proxyRes', (proxyRes, req, res) => {
            console.log('Received Response from the Target:', proxyRes.statusCode, req.url);
          });
        },
      },
    },
    cors: true, // 启用CORS
    host: '0.0.0.0', // 允许外部访问
    port: 3000, // 指定端口
  },

})
